﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Simple.Repository.Migrations
{
    public partial class _10 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<Guid>(
                name: "OrganizationId",
                table: "SysClasses",
                type: "char(36)",
                nullable: true,
                comment: "机构Id",
                collation: "ascii_general_ci");

            migrationBuilder.AddColumn<Guid>(
                name: "OrganizationId",
                table: "Childrens",
                type: "char(36)",
                nullable: true,
                comment: "机构Id",
                collation: "ascii_general_ci");

            migrationBuilder.CreateTable(
                name: "Parent",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, comment: "主键", collation: "ascii_general_ci"),
                    Name = table.Column<string>(type: "longtext", nullable: true, comment: "名字")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    PhoneNumber = table.Column<string>(type: "longtext", nullable: true, comment: "手机号码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Workplace = table.Column<string>(type: "longtext", nullable: true, comment: "工作单位")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Degree = table.Column<int>(type: "int", nullable: true, comment: "学历"),
                    IsOpenWechat = table.Column<bool>(type: "tinyint(1)", nullable: false, comment: "是否开通微信端"),
                    IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: "软删标记"),
                    CreatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "创建时间"),
                    CreatedUserId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "创建用户Id", collation: "ascii_general_ci"),
                    UpdatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "更新时间"),
                    UpdatedUserId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "更新用户Id", collation: "ascii_general_ci"),
                    OrganizationId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "机构Id", collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Parent", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "ChildrenParent",
                columns: table => new
                {
                    ChildId = table.Column<Guid>(type: "char(36)", nullable: false, comment: "幼儿id", collation: "ascii_general_ci"),
                    ParentId = table.Column<Guid>(type: "char(36)", nullable: false, comment: "家长Id", collation: "ascii_general_ci"),
                    Relationship = table.Column<int>(type: "int", nullable: false, comment: "家长关系")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ChildrenParent", x => new { x.ChildId, x.ParentId });
                    table.ForeignKey(
                        name: "FK_ChildrenParent_Childrens_ChildId",
                        column: x => x.ChildId,
                        principalTable: "Childrens",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ChildrenParent_Parent_ParentId",
                        column: x => x.ParentId,
                        principalTable: "Parent",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "幼儿家长关系表")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_ChildrenParent_ParentId_ChildId",
                table: "ChildrenParent",
                columns: new[] { "ParentId", "ChildId" });
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "ChildrenParent");

            migrationBuilder.DropTable(
                name: "Parent");

            migrationBuilder.DropColumn(
                name: "OrganizationId",
                table: "SysClasses");

            migrationBuilder.DropColumn(
                name: "OrganizationId",
                table: "Childrens");
        }
    }
}
